#!/bin/sh

ROOT=$1
LIST=$2

function copybin
{
	root=$1
	bin=$2

	if [ -e $root/$bin ]; then
		rm -f $root/$bin
	fi
	cp -P $bin $root/$bin
	if [ -h $bin ]; then
		linkbin=`readlink $bin`
		if ! `echo $linkbin | grep ^/`; then
			linkbin=`dirname $bin`/$linkbin
		fi	
		copybin $root $linkbin
	fi

	return
}

while read line; do 
	if [ "$line" = "" ]; then
		continue;
	fi

	bin=`which $line`
	if [ "$bin" = "" ]; then
		echo "Can't find file $line"
		exit -1
	fi

	copybin $ROOT $bin
	$NK_TOOLS/findlib.sh $ROOT $bin 
done < $LIST


